package com.pos.uniplugin_all;

import android.content.Context;
import android.os.RemoteException;

import com.sunmi.printerx.PrinterSdk;
import com.sunmi.printerx.SdkException;
import com.sunmi.printerx.api.PrintResult;

import java.util.List;

public class Clash {
    public PrinterSdk.Printer selectPrinter;
    /**
     * 初始化默认打印机作为待操作的打印设备
     */
    public void initPrinter(Context context) {
        try {
            PrinterSdk.getInstance().getPrinter(context, new PrinterSdk.PrinterListen() {
                @Override
                public void onDefPrinter(PrinterSdk.Printer printer) {
                    selectPrinter = printer;
                }

                @Override
                public void onPrinters(List<PrinterSdk.Printer> printers) {

                }
            });
        } catch (SdkException e) {
            e.printStackTrace();
        }
    }
    /**
     * 打开钱箱
     */
    public void open(openResult result){
        //打开钱箱1
        try {
            selectPrinter.cashDrawerApi().open(new PrintResult() {
                @Override
                public void onResult(int i, String s) throws RemoteException {
//                    tvCashStatus.setText("resultCode: " + i + " message: " + s);
                    s="测试成功";
                    result.result(i, s);
                }
            });
        } catch (SdkException e) {
            e.printStackTrace();
        }
    }

    public interface openResult{
        void result(int i, String s);
    }
}
